package com.sanchunhui.psc.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.sanchunhui.psc.R
import com.sanchunhui.psc.common.BaseConstant
import com.sanchunhui.psc.data.protocol.Member
import com.sanchunhui.psc.utils.GlideUtils
import kotlinx.android.synthetic.main.item_members.view.*

/**
 * @Author zyx
 * @Date 2021/7/22-13:17
 * @Dscribe
 */
class TeamMembersAdapter(context: Context) : BaseRecyclerViewAdapter<Member, TeamMembersAdapter.ViewHolder>(context) {

    var leadeMemberId : Int = 0

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.item_members, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val model = dataList[position]
        holder.itemView.mMemberNameTv.text = model.name
        if (leadeMemberId == model.id) {
            holder.itemView.mLeaderIcon.visibility = View.VISIBLE
        } else {
            holder.itemView.mLeaderIcon.visibility = View.GONE

        }
        //加载成员头像
        GlideUtils.loadUrlImage(mContext,BaseConstant.IMAGE_SERVER_ADDRESS_URL+"${model.id%1000}/${model.id}.jpg",holder.itemView.mMemberIconIv)

    }

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
}